<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* @framework : Codeigniter Framework
*
* @author: fatangel26
*
*/

	class Pages_model extends CI_Model
	{
	    protected  $_table;

		public function __construct()
		{
			parent::__construct();

            $this->load->database();

            $this->_table = 'tbl_pages';
		}

        /*Basic Method*/
        public function select($data = array())
        {
            if(empty($data))
            {
                $query = $this->db->get($this->_table);

                if($query->num_rows()>0)
                    return $query->result_object();
            }
            elseif(count($data) == 1)
            {
                $query = $this->db->get_where($this->_table, $data);

                if($query->num_rows()>0)
                    return $query->row();
            }
            else
            {
                if(isset($data['pages_name']) && isset($data['pages_id']))
                    $this->db->where(array('pages_name' => $data['pages_name'], 'pages_id !=' => $data['pages_id']));
                if(isset($data['pages_title']) && isset($data['pages_id']))
                    $this->db->where(array('pages_title' => $data['pages_title'], 'pages_id !=' => $data['pages_id']));

                $query = $this->db->get($this->_table);

                if($query->num_rows()>0)
                    return TRUE;
            }

            return FALSE;
        }

        public function edit($page_id, $data = array())
        {
            if(isset($data['pages_status']))
                $this->db->set('pages_status', $data['pages_status']);
            if(isset($data['pages_order']))
                $this->db->set('pages_order', $data['pages_order']);
            if(isset($data['pages_name']))
                $this->db->set('pages_name', $data['pages_name']);
            if(isset($data['pages_open']))
                $this->db->set('pages_open', $data['pages_open']);
            if(isset($data['slug']))
                $this->db->set('slug', $data['slug']);
            if(isset($data['pages_title']))
                $this->db->set('pages_title', $data['pages_title']);

            $this->db->where('pages_id', $page_id);

            if($this->db->update($this->_table))
                return TRUE;
            return FALSE;
        }

        public function delete($data = array())
        {
            $query = $this->db->delete($this->_table,$data);

            if($this->db->affected_rows()>0)
                return TRUE;
            return FALSE;
        }

        public function create($data = array())
        {
            if(!empty($data))
            {
                $query = $this->db->insert($this->_table, $data);
            }

            if($this->db->affected_rows()>0)
                return TRUE;
            return FALSE;
        }

        /*Magic method*/


	}

/* End of file Pages_model.php */
/* Location: ./models/backend/pages_model.php */